home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / EXAMPLES / LOC.C < prev    next >
C/C++ Source or Header  |  1992-07-19  |  1KB  |  81 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #else
  7. #include "vogl.h"
  8. #include "vodevice.h"
  9. #endif
  10.  
  11. /*
  12.  * a routine to demonstrate using locator.
  13.  */
  14. main()
  15. {
  16.     int        i, bt, act, nchars;
  17.     short        data;
  18.     Scoord        x, y, sx, sy;
  19.     Screencoord    minx, maxx, miny, maxy;
  20.  
  21.     ginit();
  22.  
  23.     color(BLACK);
  24.     clear();
  25.  
  26.     color(BLUE);
  27.  
  28.     getviewport(&minx, &maxx, &miny, &maxy);
  29.  
  30.     ortho2((Coord)minx, (Coord)maxx, (Coord)miny, (Coord)maxy);
  31.  
  32.     /*
  33.      * draw some axes
  34.      */
  35.     move2s((Scoord)minx, (Scoord)((maxy - miny) / 2));
  36.     draw2s((Scoord)maxx, (Scoord)((maxy - miny) / 2));
  37.  
  38.     move2s((Scoord)((maxx - minx) / 2), (Scoord)miny);
  39.     draw2s((Scoord)((maxx - minx) / 2), (Scoord)maxy);
  40.  
  41.     color(GREEN);
  42.  
  43.     /*
  44.      * enable the left and middle mouse buttons
  45.      */
  46.     unqdevice(INPUTCHANGE);
  47.     qdevice(LEFTMOUSE);
  48.     qdevice(MIDDLEMOUSE);
  49.  
  50.     act = 0;
  51.  
  52.     /*
  53.      * getvaluator tells us the valuator's value. In
  54.      * this case it's the X and Y positions of the mouse.
  55.      * Note: these come back to us in screen coordinates.
  56.      */
  57.     while((bt = qread(&data)) != MIDDLEMOUSE) {
  58.         sx = getvaluator(MOUSEX);
  59.         sy = getvaluator(MOUSEY);
  60.         if (bt == -1) {
  61.             gexit();
  62.             printf("No locator device found\n");
  63.             exit(0);
  64.         } else {
  65.             if (act) {
  66.                 act = 0;
  67.                 move2s(sx, sy);
  68.                 draw2s(x, y);
  69.             } else {
  70.                 act = 1;
  71.                 x = sx;
  72.                 y = sy;
  73.             }
  74.         }
  75.         (void)qread(&data);    /* swallow the up event */
  76.     }
  77.  
  78.     gexit();
  79.  
  80. }
  81.